const TOKEN_KEY = 'token'
export const useAppStore = defineStore("app", () => {
    console.log('useAppStore init')
    const routers = ref([]);
    const token = ref(localStorage.getItem(TOKEN_KEY) || "");
    const userInfo = {
        id : 0,
        username : "",
        role_id : 0,
        role_name : "",
    }
    const setToken = tk => {
        localStorage.setItem(TOKEN_KEY, tk);
        token.value = tk;
    }
    const cacheRouteList = ref([])

    const clear = () => {
        setToken('')
        routers.value = [];
        cacheRouteList.value = []
        userInfo.id = 0
        userInfo.username = ''
    }

    return {
        token,
        setToken,
        userInfo,
        routers,
        cacheRouteList,

        clear,
    }
})